python 2d array

30

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5
Matrix = [[0 for x in range(w)] for y in range(h)] 

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5;
Matrix = [[0 for y in range(h)] for x in range(w)] 

Matrix[0][0] = 1
Matrix[0][6] = 3 # error! range... 
Matrix[6][0] = 3 # valid
from array import *

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
for r in T:
    for c in r:
        print(c,end = " ")
    print()
import numpy as np

#create array of arrays
all_arrays = np.array([[10, 20, 30, 40, 50],
                       [60, 70, 80, 90, 100],
                       [110, 120, 130, 140, 150]])

#view array of arrays
print(all_arrays)

[[ 10  20  30  40  50]
 [ 60  70  80  90 100]
 [110 120 130 140 150]]
array = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]

print(array[0])

print(array[1][2])

Comments

Submit
0 Comments